import { Component, OnInit, Output, EventEmitter, Inject } from '@angular/core';
import { Router, NavigationEnd, ActivatedRoute, Params } from '@angular/router';
import { FormsModule, Validators, FormGroup, FormControl } from '@angular/forms';
import { DataService } from '../../../services/data.service';
import { OneEditService } from './edit.service';
import * as _ from 'lodash';
import * as moment from 'moment';
import { FileUploader } from "ng2-file-upload";
import { environment } from '../../../../environments/environment';
import { AppPaginationComponent, PaginationModel } from "../../../widgets/pagination/pagination.component";
import * as flatpickr from 'flatpickr';
import { zh } from "flatpickr/dist/l10n/zh.js";
import { Util } from 'app/common/util';

@Component({
  selector: 'onetoone-edit',
  templateUrl: './edit.component.html',
  styleUrls: ['./edit.component.scss'],
  providers: [OneEditService]
})
export class OnetooneEditComponent implements OnInit {
  // lodash
  public _: any = _;
  // 获取权限按钮
  public menuResourceSet: any = sessionStorage.getItem('btn-oto');
  // 路由index
  public index: any;
  // 路由operate
  public operate: any;
  // 产品内码
  public nFundNo: any;
  // 托管户开户行
  // public bankDictionaryList = [];
  // 备案机构、受托人、托管人
  public distionary: any = {
    RECORDORG_TYPE: [],  // 备案机构
    LINK_PRINCIPAL_NO: [],   //受托人
    TRUSTEE: []   //  托管人
  }
  // 字典值
  public dictionaryList: any = {
    PRINCIPAL_CTC_TYPE: [],
    CERTIFICATE_TYPE: [],
    NEW_FUND_CATEGORY: [],
    CAPITALPRO_TYPE: [],
    VALUATION_METHOD: [],
    VALUATION_TABLE: [],
    STOP_TYPE: [],
    VALUE_DEC: [],
    PRINCIPAL_TYPE: [],
    CAPITAN_SOURCE: [],
    KERNEL_TYPE: [],
    ONLY_PAYERFIXED: [],
    ATTORN: []
  };
  // 产品方案数据 YDY=一对一
  public cpfaYDYDataList = [];
  // 法律文件数据
  public flwjYDYDataList = [];
  // 备案数据
  public baYDYDataList = [];
  // 补充协议数据
  public bcxyYDYDataList = [];
  // 账户信息数据
  public zhxxYDYDataList = [];
  // 投资信息数据
  public tzxxYDYDataList = [];
  // 清算信息数据
  public qsxxYDYDataList = [];
  // 其他数据
  public qtYDYDataList = [];
  // 历史附件数据
  public historyDataList = [];
  // 客户附件数据
  public khfjYDYDataList = [];
  // 产品方案
  public cpfaYDY: any;
  // 法律文件
  public flwjYDY: any;
  // 备案
  public baYDY: any;
  // 补充协议
  public bcxyYDY: any;
  // 账户信息
  public zhxxYDY: any;
  // 投资信息
  public tzxxYDY: any;
  // 清算信息
  public qsxxYDY: any;
  // 其他
  public qtYDY: any;
  // 历史附件
  public historyYDY: any;
  // 客户附件
  public khfjYDY: any;
  // 用于保存显示的附件列表
  public activeFileList = [];
  // 用于保存激活的文件tab大类
  public activeFileType = "";
  // 初始化定义uploader变量,用来配置input中的uploader属性
  public uploader: FileUploader = new FileUploader({});
  // 上传文件的名称
  public uploadFileName: any = "";
  // 产品上传参数
  public sAttachCode: any;
  public nAttachNo: any;
  public sAttachType: any;
  public parentCode: any;
  public parentType: any;
  public sFundType: any;
  public sCreator: any;
  public sCreatorNo: any;
  // 选择文件状态
  public fileStatus = false;
  // 附件历史数据
  public fileHistoryData: any;
  public list = [];

  public type = "a";

  // 上传文件名
  public fileName;

  public selectLabel = "1-1";

  public tempSelectLabel = "1-1";

  public step: any;

  public labelName = "";

  public currentStatus = true;

  public costList = [];

  public listCount = 5;
  // 投资经理信息
  public otoManagerList: any;
  //查询分页列表post数据
  public otoManagerBody: any = {
    nFundNo: "",
    pageIndex: 1,
    pageSize: 10,
  };
  //一对一分页配置
  public otoManagerListPageInfo: PaginationModel = {
    currentPageNum: 1,
    pageSize: 10,
    totalPages: 1,
    total: 0,
    pagesShow: 5,
    startRow: 0,
    endRow: 0,
    pageList: [5, 10, 25, 50, 100]
  };
  // 判断客户信息为新增还是修改
  public otoCustomerStatus: any;
  // 一对一客户信息
  public otoCustomerBody: any = {
    sPrincipalType: "",
    sCtcType: "",
    sCapitanSource: "",
    sLegalCtcType: "",
    sAgentCtcType: ""
  };
  // 一对一基础信息
  public otoAddOrEditBody: any = {
    sFundCategory: "",
    sIsAisle: "0",
    sPrincipalType: "0",
    sValuationTable: "",
    sCapitalproType: "",
    nContractPeriod: "",
    sValuationMethod: "",
    sBank: "",
    sStopType: "",
    nValueDec: "",
    sIsContractPeriod: "1",
    sOnlyPayerfixed: "",
    sKernelType: ""
  };
  public otoAddOrEditBodyClone: any;
  constructor(
    private route: ActivatedRoute,
    public dataService: DataService,
    public oneEditService: OneEditService,
    public router: Router
  ) {
    // 路由切换
    this.route.params.subscribe((data) => {
      this.nFundNo = data.nFundNo;
      this.operate = data.operate;
      this.index = data.index;
      // 编辑基础信息
      if (this.operate == "edit") {
        // 产品基础信息
        this.otoGetSingleProduct();
        // 客户基础信息
        this.otoGetCustomer();
        // 投资经理信息
        this.otoGetManager();
        window['$']('#attachTab').removeClass('active');
        window['$']("#attachInfo").attr('aria-expanded', "false");
        window['$']("#tab_2").removeClass('active');

        window['$']('#investTab').removeClass('active');
        window['$']("#investInfo").attr('aria-expanded', "false");
        window['$']("#tab_7").removeClass('active');

        window['$']('#customerTab').removeClass('active');
        window['$']("#customerInfo").attr('aria-expanded', "false");
        window['$']("#tab_8").removeClass('active');

        window['$']('#baseTab').addClass('active');
        window['$']("#baseInfo").attr('aria-expanded', "true");
        window['$']("#tab_1").addClass('active');
      }
    })
  }

  ngOnInit() {

    // 多选下拉框
    window['$'](".select2").select2();

    window['$']('#dBegin').attr("background", "#eeeeee");
    if (this.operate == 'add') {
      window['$']('#nContractPeriod').attr("disabled", "disabled");
    }
    // 初始化日期控件
    flatpickr.localize(zh);
    // 字典值
    this.dictionaryList = JSON.parse(localStorage.getItem("dictionaryList"));
    // 解决附件跨域问题
    this.uploader.onAfterAddingFile = (file) => { file.withCredentials = false; };

    this.getDictionary();
    // 托管行
    // this.bankDictionaryList = JSON.parse(localStorage.getItem("bankDictionaryList"));
  }
  ngAfterViewInit() {
    this.ctrlDisabled();
    let that = this;
    if (this.operate != 'edit') {
      window['$'](".select2").select2();
      window['$']('#sTrusteeSelected').select2({ width: '240px', tags: true });
      window['$']('#sTrusteeSelected').on("select2:select", function (e) {
        that.otoAddOrEditBody.sTrustee = window['$']('#sTrusteeSelected').select2("val");
      })
    }
  }


  // 加载附件树
  loadFileTree() {
    var that = this;
    this.activeFileList = [];
    let getBody = {
      "sFundType": 3,
      "nFundNo": this.nFundNo
    }
    this.oneEditService.getFileTree(getBody).subscribe((data) => {
      if (data) {
        // 赋值前清空数据
        that.cpfaYDYDataList = [];
        that.flwjYDYDataList = [];
        that.baYDYDataList = [];
        that.bcxyYDYDataList = [];
        that.zhxxYDYDataList = [];
        that.tzxxYDYDataList = [];
        that.qsxxYDYDataList = [];
        that.khfjYDYDataList = [];
        that.qtYDYDataList = [];
        that.historyDataList = [];
        _.forEach(data.subTree, function (item, index) {
          // 保存附件列表展示的tab
          that.activeFileList.push(item.sAttachCode);
          switch (item.sAttachCode) {
            case "cpfaYDY":
              that.cpfaYDY = item.subTree;
              let _cpfaYDYDataList = [];
              _.forEach(that.cpfaYDY, function (ite) {          // ite是附件小分类
                _.forEach(ite.fileList, function (it) {         // it是附件
                  it.sFundType = ite.sFundType;                 // 附件类型 2
                  it["sParentType"] = item.sAttachType;         // 附件大分类名称 产品方案
                  it["sParentCode"] = ite.sParentCode;          // 附件大分类编码 cpfaYDY
                  it["parentType"] = ite.sAttachType;           // 附件小分类名称 产品需求表
                  it["attachCode"] = ite.sAttachCode;           // 附件小分类编码 cpxqbYDD
                  it["subNodeL"] = ite.fileList.length;         // 附件小分类长度
                  it["sType"] = "";                             // 附件小分类名称
                  it["editStatus"] = "0";                       // 附件名编辑状态
                  it["fileName"] = "";                          // 附件修改名称
                  it["fileType"] = that.InterceptType(it.sAttachName);                          // 附件后缀
                  _cpfaYDYDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;     // 附件小分类名称
              });
              that.cpfaYDYDataList = _cpfaYDYDataList;
              break;
            case "flwjYDY":
              that.flwjYDY = item.subTree;
              let _flwjYDYDataList = [];
              _.forEach(that.flwjYDY, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = that.InterceptType(it.sAttachName);
                  _flwjYDYDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.flwjYDYDataList = _flwjYDYDataList;
              break;
            case "baYDY":
              that.baYDY = item.subTree;
              let _baYDYDataList = [];
              _.forEach(that.baYDY, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = that.InterceptType(it.sAttachName);
                  _baYDYDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.baYDYDataList = _baYDYDataList;
              break;
            case "bcxyYDY":
              that.bcxyYDY = item.subTree;
              let _bcxyYDYDataList = [];
              _.forEach(that.bcxyYDY, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = that.InterceptType(it.sAttachName);
                  _bcxyYDYDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.bcxyYDYDataList = _bcxyYDYDataList;
              break;
            case "zhxxYDY":
              that.zhxxYDY = item.subTree;
              let _zhxxYDYDataList = [];
              _.forEach(that.zhxxYDY, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = that.InterceptType(it.sAttachName);
                  _zhxxYDYDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.zhxxYDYDataList = _zhxxYDYDataList;
              break;
            case "tzxxYDY":
              that.tzxxYDY = item.subTree;
              let _tzxxYDYDataList = [];
              _.forEach(that.tzxxYDY, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = that.InterceptType(it.sAttachName);
                  _tzxxYDYDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.tzxxYDYDataList = _tzxxYDYDataList;
              break;
            case "qsxxYDY":
              that.qsxxYDY = item.subTree;
              let _qsxxYDYDataList = [];
              _.forEach(that.qsxxYDY, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = that.InterceptType(it.sAttachName);
                  _qsxxYDYDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.qsxxYDYDataList = _qsxxYDYDataList;
              break;
            case "qtYDY":
              that.qtYDY = item.subTree;
              let _qtYDYDataList = [];
              _.forEach(that.qtYDY, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = that.InterceptType(it.sAttachName);
                  _qtYDYDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.qtYDYDataList = _qtYDYDataList;
              break;
            case "khfjYDY":
              that.khfjYDY = item.subTree;
              let _khfjYDYDataList = [];
              _.forEach(that.khfjYDY, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = that.InterceptType(it.sAttachName);
                  _khfjYDYDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.khfjYDYDataList = _khfjYDYDataList;
              break;
            case "historyYDY":
              that.historyYDY = item.subTree;
              let _historyDataList = [];
              _.forEach(that.historyYDY, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = that.InterceptType(it.sAttachName);
                  _historyDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.historyDataList = _historyDataList;
              break;
          }
        })
        setTimeout(() => {
          that.activeFileTab();
        }, 200)
      }
    })
  }
  // 产品树文件分类新增对象
  addSubTreeItem(item, type) {
    let that = this;
    let index;
    this.activeFileType = item.sParentCode;
    let newItem: any = {
      sType: item.sType,              // 小分类名称
      subNodeL: item.subNodeL + 1,    // 长度+1
      attachCode: item.attachCode,    // 小分类编码
      parentType: item.parentType,    // 小分类名称
      sParentType: item.sParentType,  // 大分类名称
      sParentCode: item.sParentCode,  // 大分类编码
      sAttachParentType: "",
      nAttachNo: "",
      nFundNo: "",
      sAttachType: item.parentType,   // 小分类名称
      sAttachCode: item.attachCode,   // 小分类编码
      sLinkFundnos: null,
      sAttachName: null,
      sLinkPrincipalNo: null,
      sLinkPrincipal: null,
      sStatus: null,
      dCreateTime: null,
      sCreator: null,
      sCreatorNo: null,
      nVersion: null,
      sAttachParentCode: null,
      sPath: null,
      nLastAttachNo: null,
      sFundType: item.sFundType,
      editStatus: "0",
      fileName: "",
      fileType: ""
    }
    switch (type) {
      case "cpfaYDY":
        index = _.indexOf(this.cpfaYDYDataList, item);
        this.cpfaYDYDataList[index].sType = "";
        this.cpfaYDYDataList.splice(index, 0, newItem);
        break;
      case "flwjYDY":
        index = _.indexOf(this.flwjYDYDataList, item);
        this.flwjYDYDataList[index].sType = "";
        this.flwjYDYDataList.splice(index, 0, newItem);
        break;
      case "baYDY":
        index = _.indexOf(this.baYDYDataList, item);
        this.baYDYDataList[index].sType = "";
        this.baYDYDataList.splice(index, 0, newItem);
        break;
      case "bcxyYDY":
        index = _.indexOf(this.bcxyYDYDataList, item);
        this.bcxyYDYDataList[index].sType = "";
        this.bcxyYDYDataList.splice(index, 0, newItem);
        break;
      case "zhxxYDY":
        index = _.indexOf(this.zhxxYDYDataList, item);
        this.zhxxYDYDataList[index].sType = "";
        this.zhxxYDYDataList.splice(index, 0, newItem);
        break;
      case "tzxxYDY":
        index = _.indexOf(this.tzxxYDYDataList, item);
        this.tzxxYDYDataList[index].sType = "";
        this.tzxxYDYDataList.splice(index, 0, newItem);
        break;
      case "qsxxYDY":
        index = _.indexOf(this.qsxxYDYDataList, item);
        this.qsxxYDYDataList[index].sType = "";
        this.qsxxYDYDataList.splice(index, 0, newItem);
        break;
      case "qtYDY":
        index = _.indexOf(this.qtYDYDataList, item);
        this.qtYDYDataList[index].sType = "";
        this.qtYDYDataList.splice(index, 0, newItem);
        break;
      case "khfjYDY":
        index = _.indexOf(this.khfjYDYDataList, item);
        this.khfjYDYDataList[index].sType = "";
        this.khfjYDYDataList.splice(index, 0, newItem);
        break;
      case "historyYDY":
        index = _.indexOf(this.historyDataList, item);
        this.historyDataList[index].sType = "";
        this.historyDataList.splice(index, 0, newItem);
        break;
    }
  }
  // 显示上传文件框
  showUploadModal(item) {
    this.activeFileType = item.sParentCode;
    // 上传文件必填字段
    this.sAttachCode = item.attachCode;
    this.sAttachType = item.parentType;
    this.parentCode = item.sParentCode;
    this.parentType = item.sParentType;
    this.sFundType = item.sFundType;
    this.sCreator = sessionStorage.getItem('token');
    this.sCreatorNo = sessionStorage.getItem('token');
    if (item.nAttachNo == null) {
      this.nAttachNo = "";
    } else {
      this.nAttachNo = item.nAttachNo;
    }
    window['$']('#uploadModel').modal('show');
  }
  // 获取上传文件的名称
  selectedFileOnChanged(event: any) {
    this.uploadFileName = event.target.value;
    this.fileStatus = true;
  }
  // 上传文件
  uploadFile() {
    let that = this;
    let reg = /[\#&*|/:"<>?]/gi;
    if (reg.test(_.last(this.uploader.queue).file.name)) {
      window["swal"]("提示", "文件名含有特殊字符!", "warning");
    } else {
      let fileItem = _.last(this.uploader.queue);
      fileItem.url = environment.server + '/pms/v1/common/fundFile/file?token=' + sessionStorage.getItem('token');
      fileItem.method = "POST";
      // 关联input框的“name”属性
      fileItem.alias = "file";
      fileItem.formData = [
        { key: "fileName", value: _.last(this.uploader.queue).file.name },
        { key: "nFundNo", value: this.nFundNo },
        { key: "nAttachNo", value: this.nAttachNo },
        { key: "sAttachCode", value: this.sAttachCode },
        { key: "sAttachType", value: this.sAttachType },
        { key: "parentCode", value: this.parentCode },
        { key: "parentType", value: this.parentType },
        { key: "sFundType", value: this.sFundType },
        { key: "sCreator", value: this.sCreator },
        { key: "sCreatorNo", value: this.sCreatorNo }
      ],
        // 添加 POST 其他参数
        this.uploader.onBuildItemForm = (item, form) => {
          _.forEach(fileItem.formData, item => {
            form.append(item.key, item.value);
          });
        };
      window['swal']({
        title: "提示",
        text: "是否确定上传 " + _.last(this.uploader.queue).file.name + " 附件?",
        type: "warning",
        showCancelButton: true,
        closeOnConfirm: false,
        confirmButtonText: "确认",
        confirmButtonColor: "#DD6B55",
        cancelButtonText: "取消",
        showLoaderOnConfirm: true,
      }, function (isConfirm) {
        if (isConfirm) {
          // 开始上传
          fileItem.upload();
          // 上传一个文件成功的回调
          fileItem.onSuccess = function (response, status, headers) {
            let resVal = JSON.parse(response);
            if (resVal.msg == "成功") {
              window["swal"]("成功", "文件上传成功!", "success");
              window['$']('#uploadModel').modal('hide');
              that.clearFileQueue();
              that.loadFileTree();
            } else {
              window["swal"](resVal.msg, resVal.detailMsg, "error");
              window['$']('#uploadModel').modal('hide');
              that.clearFileQueue();
            }
          }
        }
      })
    }
  }

  // 清除FileUploader上传队列中的所有文件
  clearFileQueue() {
    this.uploader.clearQueue();
    this.fileStatus = false;
    window['$']('#fileInput').val("");
  }

  // 下载附件
  downLoadFile(item) {
    if (item.nAttachNo) {
      Util.attachDownload([item.nAttachNo]);
    } else {
      window['swal']("提示", "暂无文件下载", "warning");
    }
  }

  // 查看历史文件
  showHistoryVersion(item) {
    let that = this;
    this.activeFileType = item.sParentCode;
    this.oneEditService.getFileHistory(item.nAttachNo).subscribe(data => {
      if (data) {
        that.fileHistoryData = data;
        // 附件后缀
        _.forEach(that.fileHistoryData, function (item) {
          item["fileType"] = that.InterceptType(item.sAttachName);
        })
        window['$']("#detail-his-list").modal('show');
      } else {
        window['swal']("提示", "暂无文件", "warning");
      }
    })
  }
  // 删除文件
  delFile(item) {
    let that = this;
    window["swal"]({
      title: "注意",
      text: "是否确定删除 " + item.sAttachName + " 附件？",
      type: "warning",
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: false
    }, function (isConfirm) {
      if (isConfirm) {
        that.oneEditService.delFile(item.nAttachNo).subscribe(data => {
          if (data) {
            window['swal']("成功", "文件已删除！", "success");
            window['$']("#detail-his-list").modal('hide');
            that.loadFileTree();
          } else {
            window['swal']("失败", data.msg, "error");
          }
        })
      }
    })
  }
  // 编辑附件名称
  editFileName(item, type) {
    let that = this;
    this.activeFileType = item.sParentCode;
    let len = item.sAttachName.length;
    let lastDotIndex = item.sAttachName.lastIndexOf(".");
    let index;
    switch (type) {
      case "cpfaYDY":
        index = _.indexOf(this.cpfaYDYDataList, item);
        this.cpfaYDYDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.cpfaYDYDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.cpfaYDYDataList[index].editStatus = "1";
        break;
      case "flwjYDY":
        index = _.indexOf(this.flwjYDYDataList, item);
        this.flwjYDYDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.flwjYDYDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.flwjYDYDataList[index].editStatus = "1";
        break;
      case "baYDY":
        index = _.indexOf(this.baYDYDataList, item);
        this.baYDYDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.baYDYDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.baYDYDataList[index].editStatus = "1";
        break;
      case "bcxyYDY":
        index = _.indexOf(this.bcxyYDYDataList, item);
        this.bcxyYDYDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.bcxyYDYDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.bcxyYDYDataList[index].editStatus = "1";
        break;
      case "zhxxYDY":
        index = _.indexOf(this.zhxxYDYDataList, item);
        this.zhxxYDYDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.zhxxYDYDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.zhxxYDYDataList[index].editStatus = "1";
        break;
      case "tzxxYDY":
        index = _.indexOf(this.tzxxYDYDataList, item);
        this.tzxxYDYDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.tzxxYDYDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.tzxxYDYDataList[index].editStatus = "1";
        break;
      case "qsxxYDY":
        index = _.indexOf(this.qsxxYDYDataList, item);
        this.qsxxYDYDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.qsxxYDYDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.qsxxYDYDataList[index].editStatus = "1";
        break;
      case "qtYDY":
        index = _.indexOf(this.qtYDYDataList, item);
        this.qtYDYDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.qtYDYDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.qtYDYDataList[index].editStatus = "1";
        break;
      case "khfjYDY":
        index = _.indexOf(this.khfjYDYDataList, item);
        this.khfjYDYDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.khfjYDYDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.khfjYDYDataList[index].editStatus = "1";
        break;
      case "historyYDY":
        index = _.indexOf(this.historyDataList, item);
        this.historyDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.historyDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.historyDataList[index].editStatus = "1";
        break;
    }
  }
  // 修改附件名
  changeFileName(item) {
    let that = this;
    // 去掉附件名首尾空格
    let filename = _.trim(item.fileName);
    if (filename !== "" && filename !== null) {
      let reg = /[\#&*|/:"<>?]/gi;
      if (reg.test(filename)) {
        window["swal"]("提示", "文件名含有特殊字符!", "warning");
      } else {
        let newFileName = encodeURI(filename) + item.fileType;
        window['swal']({
          title: "提示",
          text: "附件名称是否确定修改为 " + filename + " ?",
          type: "warning",
          showCancelButton: true,
          closeOnConfirm: false,
          confirmButtonText: "确认",
          confirmButtonColor: "#DD6B55",
          cancelButtonText: "取消",
          showLoaderOnConfirm: true,
        }, function (isConfirm) {
          if (isConfirm) {
            that.oneEditService.changeFileName(item.nAttachNo, newFileName).subscribe(data => {
              if (data) {
                window['swal']("成功", "附件名修改成功!", "success");
                that.loadFileTree();
              }
            })
          }
        })
      }
    } else {
      window['swal']("注意", "附件名不能为空", "warning")
    }
  }
  // 取消编辑附件名
  cancelEditFileName(item, type) {
    let index;
    switch (type) {
      case "cpfaYDY":
        index = _.indexOf(this.cpfaYDYDataList, item);
        this.cpfaYDYDataList[index].editStatus = "0";
        break;
      case "flwjYDY":
        index = _.indexOf(this.flwjYDYDataList, item);
        this.flwjYDYDataList[index].editStatus = "0";
        break;
      case "baYDY":
        index = _.indexOf(this.baYDYDataList, item);
        this.baYDYDataList[index].editStatus = "0";
        break
      case "bcxyYDY":
        index = _.indexOf(this.bcxyYDYDataList, item);
        this.bcxyYDYDataList[index].editStatus = "0";
        break;
      case "zhxxYDY":
        index = _.indexOf(this.zhxxYDYDataList, item);
        this.zhxxYDYDataList[index].editStatus = "0";
        break;
      case "tzxxYDY":
        index = _.indexOf(this.tzxxYDYDataList, item);
        this.tzxxYDYDataList[index].editStatus = "0";
        break;
      case "qsxxYDY":
        index = _.indexOf(this.qsxxYDYDataList, item);
        this.qsxxYDYDataList[index].editStatus = "0";
        break;
      case "qtYDY":
        index = _.indexOf(this.qtYDYDataList, item);
        this.qtYDYDataList[index].editStatus = "0";
        break;
      case "khfjYDY":
        index = _.indexOf(this.khfjYDYDataList, item);
        this.khfjYDYDataList[index].editStatus = "0";
        break;
      case "historyYDY":
        index = _.indexOf(this.historyDataList, item);
        this.historyDataList[index].editStatus = "0";
        break;
    }
  }
  // 切换tab清空附件类型
  clearFileType() {
    this.activeFileType = "";
  }
  // 激活文件tab
  activeFileTab() {
    let that = this;
    window['$']('#cpfaYDY_List').removeClass('active');
    window['$']('#tab_9').removeClass('active');
    window['$']("#cpfaYDY_Content").attr('aria-expanded', "false");
    window['$']('#flwjYDY_List').removeClass('active');
    window['$']('#tab_10').removeClass('active');
    window['$']("#flwjYDY_Content").attr('aria-expanded', "false");
    window['$']('#baYDY_List').removeClass('active');
    window['$']('#tab_11').removeClass('active');
    window['$']("#baYDY_Content").attr('aria-expanded', "false");
    window['$']('#bcxyYDY_List').removeClass('active');
    window['$']('#tab_12').removeClass('active');
    window['$']("#bcxyYDY_Content").attr('aria-expanded', "false");
    window['$']('#zhxxYDY_List').removeClass('active');
    window['$']('#tab_13').removeClass('active');
    window['$']("#zhxxYDY_Content").attr('aria-expanded', "false");
    window['$']('#tzxxYDY_List').removeClass('active');
    window['$']('#tab_14').removeClass('active');
    window['$']("#tzxxYDY_Content").attr('aria-expanded', "false");
    window['$']('#qsxxYDY_List').removeClass('active');
    window['$']('#tab_15').removeClass('active');
    window['$']("#qsxxYDY_Content").attr('aria-expanded', "false");
    window['$']('#qtYDY_List').removeClass('active');
    window['$']('#tab_16').removeClass('active');
    window['$']("#qtYDY_Content").attr('aria-expanded', "false");
    window['$']('#khfjYDY_List').removeClass('active');
    window['$']('#tab_17').removeClass('active');
    window['$']("#khfjYDY_Content").attr('aria-expanded', "false");
    window['$']('#history_List').removeClass('active');
    window['$']('#tab_18').removeClass('active');
    window['$']("#history_Content").attr('aria-expanded', "false");
    if (this.activeFileType == "") {
      this.activeFileType = this.activeFileList[0];
    }
    switch (this.activeFileType) {
      case "cpfaYDY":
        window['$']('#cpfaYDY_List').addClass('active');
        window['$']('#tab_9').addClass('active');
        window['$']("#cpfaYDY_Content").attr('aria-expanded', "true");
        break;
      case "flwjYDY":
        window['$']('#flwjYDY_List').addClass('active');
        window['$']('#tab_10').addClass('active');
        window['$']("#flwjYDY_Content").attr('aria-expanded', "true");
        break;
      case "baYDY":
        window['$']('#baYDY_List').addClass('active');
        window['$']('#tab_11').addClass('active');
        window['$']("#baYDY_Content").attr('aria-expanded', "true");
        break;
      case "bcxyYDY":
        window['$']('#bcxyYDY_List').addClass('active');
        window['$']('#tab_12').addClass('active');
        window['$']("#bcxyYDY_Content").attr('aria-expanded', "true");
        break;
      case "zhxxYDY":
        window['$']('#zhxxYDY_List').addClass('active');
        window['$']('#tab_13').addClass('active');
        window['$']("#zhxxYDY_Content").attr('aria-expanded', "true");
        break;
      case "tzxxYDY":
        window['$']('#tzxxYDY_List').addClass('active');
        window['$']('#tab_14').addClass('active');
        window['$']("#tzxxYDY_Content").attr('aria-expanded', "true");
        break;
      case "qsxxYDY":
        window['$']('#qsxxYDY_List').addClass('active');
        window['$']('#tab_15').addClass('active');
        window['$']("#qsxxYDY_Content").attr('aria-expanded', "true");
        break;
      case "qtYDY":
        window['$']('#qtYDY_List').addClass('active');
        window['$']('#tab_16').addClass('active');
        window['$']("#qtYDY_Content").attr('aria-expanded', "true");
        break;
      case "khfjYDY":
        window['$']('#khfjYDY_List').addClass('active');
        window['$']('#tab_17').addClass('active');
        window['$']("#khfjYDY_Content").attr('aria-expanded', "true");
        break;
      case "historyYDY":
        window['$']('#history_List').addClass('active');
        window['$']('#tab_18').addClass('active');
        window['$']("#history_Content").attr('aria-expanded', "true");
        break;
    }
  }
  // 查询单个产品基础信息
  otoGetSingleProduct() {
    let that = this;
    this.oneEditService.otoGetSingleProduct(this.nFundNo).subscribe(data => {
      if (data) {
        that.otoAddOrEditBody = data;
        that.otoAddOrEditBodyClone = _.clone(data);
        that.otoIsAisle();
        that.otoIsPrincipalType();
        that.IsContractPeriod();
        if (that.otoAddOrEditBody.sValuationTable == null) {
          that.otoAddOrEditBody.sValuationTable = "";
        }
        setTimeout(function () {
          // 多选下拉框
          window['$'](".select2").select2();
          window['$']('#sTrusteeSelected').select2({ width: '240px', tags: true });
          window['$']('#sTrusteeSelected').on("select2:select", function (e) {
            that.otoAddOrEditBody.sTrustee = window['$']('#sTrusteeSelected').select2("val");
          })
        }, 100);
      }
    })
  }
  // 查询客户信息
  otoGetCustomer() {
    let that = this;
    this.oneEditService.otoGetCustomer(this.nFundNo).subscribe(data => {
      if (data) {
        if (data.nCustomerNo !== "" && data.nCustomerNo !== null) {
          that.otoCustomerBody = data;
          that.otoCustomerStatus = true;
          // 委托人证件有效期
          if (that.otoCustomerBody.sIsctcLongtime == "1") {
            that.otoCustomerBody.sIsctcLongtime = true;
            that.otoCustomerBody.dCtcValid = "";
            window['$']('#dCtcValid').attr('disabled', 'disabled');
            window['$']('#dCtcValid').css('background', "#eee")
          } else {
            that.otoCustomerBody.sIsctcLongtime = false;
            window['$']('#dCtcValid').removeAttr('disabled');
            window['$']('#dCtcValid').css('background', "#ffffff")
          }
          // 法人证件有效期
          if (that.otoCustomerBody.sIslcLongtime == "1") {
            that.otoCustomerBody.sIslcLongtime = true;
            that.otoCustomerBody.dLegalCtcValid = "";
            window['$']('#dLegalCtcValid').attr('disabled', 'disabled');
            window['$']('#dLegalCtcValid').css('background', "#eee");
          } else {
            that.otoCustomerBody.sIslcLongtime = false;
            window['$']('#dLegalCtcValid').removeAttr('disabled');
            window['$']('#dLegalCtcValid').css('background', "#ffffff");
          }
          // 经办人证件有效期
          if (that.otoCustomerBody.sIsacLongtime == "1") {
            that.otoCustomerBody.sIsacLongtime = true;
            that.otoCustomerBody.dAgentCtcValid = "";
            window['$']('#dAgentCtcValid').attr('disabled', 'disabled');
            window['$']('#dAgentCtcValid').css('background', "#eee")
          } else {
            that.otoCustomerBody.sIsacLongtime = false;
            window['$']('#dAgentCtcValid').removeAttr('disabled');
            window['$']('#dAgentCtcValid').css('background', "#ffffff")
          }
        } else {
          that.otoCustomerBody = {};
          that.otoCustomerStatus = false;
        }
      }
    })
  }
  // 投资经理信息
  otoGetManager(pageNum?, pageSize?) {
    let that = this;
    this.otoManagerBody.nFundNo = this.nFundNo;
    this.otoManagerBody.pageIndex = pageNum ? pageNum : this.otoManagerListPageInfo.currentPageNum;
    this.otoManagerBody.pageSize = pageSize ? pageSize : this.otoManagerListPageInfo.pageSize;
    this.oneEditService.otoGetManager(this.otoManagerBody).subscribe(data => {
      if (data) {
        that.otoManagerList = data.list;
        that.otoManagerListPageInfo.currentPageNum = data.pageNum;
        that.otoManagerListPageInfo.totalPages = data.pages;
        that.otoManagerListPageInfo.total = data.total;
        that.otoManagerListPageInfo.startRow = data.startRow;
        that.otoManagerListPageInfo.endRow = data.endRow;
      }
    })
  }
  // 投资经理切换页
  otoManagerPagesizeChange(pageSize: number) {
    if (pageSize !== this.otoManagerListPageInfo.pageSize) {
      this.otoManagerListPageInfo.pageSize = pageSize;
      this.otoGetManager();
    }
  }
  // 投资经理分页
  otoManagerPageNavigation(currentPageNum: number) {
    this.otoManagerListPageInfo.currentPageNum = currentPageNum;
    this.otoGetManager(this.otoManagerListPageInfo.currentPageNum, this.otoManagerListPageInfo.pageSize);
  }
  // 新增或编辑产品基础信息
  otoAddOrEditBasicInfo(type) {
    let that = this;
    this.otoAddOrEditBody.sFundType = "3";
    if (this.requireAdd()) {
      if (this.beforeRunTime()) {
        window["swal"]({
          title: "提示",
          text: "是否确定保存基础信息?",
          type: "warning",
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          showCancelButton: true,
          closeOnConfirm: false,
          closeOnCancel: true,
          showLoaderOnConfirm: true
        },
          function (isConfirm) {
            if (isConfirm) {
              if (type == 'add') {
                // 新增产品默认为运行状态
                that.otoAddOrEditBody.sStatusRunning = "1";
                that.otoAddOrEditBody.sStatus = "0";
                let publicUrl: any = { "url": "/pages/onetoone/new/detail/add" };
                that.oneEditService.otoAddProduct(that.otoAddOrEditBody).subscribe(data => {
                  if (data) {
                    window['swal']("成功", "新增成功!", "success");
                    that.otoAddOrEditBody = {};
                    that.dataService.public_url.emit(publicUrl);
                    that.router.navigate(['/pages/onetooneList/wcl']);
                  }
                })
              }
              if (type == 'edit') {
                delete that.otoAddOrEditBody.nValueDecZh;
                delete that.otoAddOrEditBody.sIsHandZh;
                that.oneEditService.otoEditProduct(that.otoAddOrEditBody).subscribe(data => {
                  if (data) {
                    that.otoGetCustomer();
                    window['swal']("成功", "修改成功!", "success");
                  }
                })
              }
            }
          })
      } else {
        window['swal']("提示", "到期日不能比起始运作日期早", "warning");
      }
    }
  }
  // 创设-(起始运作日期/到期日)-校验
  beforeRunTime() {
    if (this.otoAddOrEditBody.dBegin !== "" && this.otoAddOrEditBody.dBegin !== null && this.otoAddOrEditBody.dEnd !== "" && this.otoAddOrEditBody.dEnd !== null) {
      if (this.otoAddOrEditBody.dBegin == this.otoAddOrEditBody.dEnd) {
        return true;
      } else {
        if (moment(this.otoAddOrEditBody.dBegin).isBefore(this.otoAddOrEditBody.dEnd)) {
          return true;
        } else {
          return false;
        }
      }
    } else {
      return true;
    }
  }
  // 是否通道类专户控制
  otoIsAisle() {
    if (this.otoAddOrEditBody.sIsAisle == '1') {
      window['$']('#sCapitalpro').removeAttr("disabled");
      window['$']('#sCapitalproType').removeAttr("disabled");
    }
    if (this.otoAddOrEditBody.sIsAisle == '0') {
      this.otoAddOrEditBody.sCapitalpro = "";
      this.otoAddOrEditBody.sCapitalproType = "";
      window['$']('#sCapitalpro').attr("disabled", "disabled");
      window['$']('#sCapitalproType').attr("disabled", "disabled");
    }
  }
  // 委托人类型(是否资管产品)
  otoIsPrincipalType() {
    if (this.otoAddOrEditBody.sPrincipalType == '1') {
      window['$']('#sFrontendCode').removeAttr("disabled");
      window['$']('#sFrontendName').removeAttr("disabled");
    }
    if (this.otoAddOrEditBody.sPrincipalType == '0') {
      this.otoAddOrEditBody.sFrontendCode = "";
      this.otoAddOrEditBody.sFrontendName = "";
      window['$']('#sFrontendCode').attr("disabled", "disabled");
      window['$']('#sFrontendName').attr("disabled", "disabled");
    }
  }
  // 新增或编辑客户信息
  otoAddOrEditCustomer() {
    let that = this;
    // otoCustomerStatus = true 为修改状态
    // otoCustomerStatus = false 为新增状态
    window["swal"]({
      title: "提示",
      text: "是否确定保存客户信息?",
      type: "warning",
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: true
    },
      function (isConfirm) {
        if (isConfirm) {
          if (that.otoCustomerStatus) {
            that.oneEditService.otoEditCustomer(that.otoCustomerBody).subscribe(data => {
              if (data) {
                window['swal']("成功", "修改成功!", "success");
                that.otoGetSingleProduct();
              }
            })
          } else {
            that.otoCustomerBody.nFundNo = that.nFundNo;
            that.oneEditService.otoAddCustomer(that.otoCustomerBody).subscribe(data => {
              if (data) {
                window['swal']("成功", "新增成功!", "success");
                that.otoGetCustomer();
                that.otoGetSingleProduct();
              }
            })
          }
        }
      })

  }
  // 委托人证件有效期
  ctcLongtime() {
    if (this.otoCustomerBody.sIsctcLongtime == true) {
      this.otoCustomerBody.dCtcValid = "";
      window['$']('#dCtcValid').attr('disabled', 'disabled');
      window['$']('#dCtcValid').css('background', "#eee");
    } else {
      window['$']('#dCtcValid').removeAttr('disabled');
      window['$']('#dCtcValid').css('background', "#ffffff")
    }
  }
  // 法人证件有效期
  lcLongtime() {
    if (this.otoCustomerBody.sIslcLongtime == true) {
      this.otoCustomerBody.dLegalCtcValid = "";
      window['$']('#dLegalCtcValid').attr('disabled', 'disabled');
      window['$']('#dLegalCtcValid').css('background', "#eee");
    } else {
      window['$']('#dLegalCtcValid').removeAttr('disabled');
      window['$']('#dLegalCtcValid').css('background', "#ffffff");
    }
  }
  // 经办人证件有效期
  acLongtime() {
    if (this.otoCustomerBody.sIsacLongtime == true) {
      this.otoCustomerBody.dAgentCtcValid = "";
      window['$']('#dAgentCtcValid').attr('disabled', 'disabled');
      window['$']('#dAgentCtcValid').css('background', "#eee")
    } else {
      window['$']('#dAgentCtcValid').removeAttr('disabled');
      window['$']('#dAgentCtcValid').css('background', "#ffffff")
    }
  }
  // 已成立产品信息修改,修改信息后去到审核面板(不直接修改信息)
  otoCheckProductEdit() {
    let that = this;
    let businessType = "1";
    this.otoAddOrEditBody.sFundType = "3";
    // 产品业务类型,修改(1)、续约(2)、终止(3)、开始运作(4)
    if (this.requireAdd()) {
      if (this.beforeRunTime()) {
        if (Util.objectCheck(that.otoAddOrEditBody, that.otoAddOrEditBodyClone)) {
          window['swal']("提示", "信息未修改，不会生成修改审核记录", "warning");
        } else {
          window["swal"]({
            title: "提示",
            text: "是否确定保存基础信息?",
            type: "warning",
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            showCancelButton: true,
            closeOnConfirm: false,
            closeOnCancel: true,
            showLoaderOnConfirm: true
          },
            function (isConfirm) {
              if (isConfirm) {
                delete that.otoAddOrEditBody.nValueDecZh;
                delete that.otoAddOrEditBody.sIsHandZh;
                that.oneEditService.operationType(that.otoAddOrEditBody, businessType).subscribe(data => {
                  if (data) {
                    window['swal']("成功", "请等待产品审核!", "success");
                    that.otoGetSingleProduct();
                  }
                })
              }
            })
        }
      } else {
        window['swal']("提示", "到期日不能比起始运作日期早", "warning");
      }
    }
  }
  // 判断合同期限
  IsContractPeriod() {
    if (this.otoAddOrEditBody.sIsContractPeriod == "1") {
      this.otoAddOrEditBody.nContractPeriod = "";
      window['$']('#nContractPeriod').attr("disabled", "disabled");
      window['$']('#nContractPeriod').css("background", "#eee");
    }
    else if (this.otoAddOrEditBody.sIsContractPeriod == "0") {
      window['$']('#nContractPeriod').removeAttr("disabled", "disabled");
      window['$']('#nContractPeriod').css("background", "#ffffff");
    }
  }
  // 新增、编辑必填校验
  requireAdd() {
    let that = this;
    let requiredAddTip = [];
    let sFullName = _.trim(this.otoAddOrEditBody.sFullName);
    let sFundName = _.trim(this.otoAddOrEditBody.sFundName);
    if (sFullName == "" || sFullName == null) {
      requiredAddTip.push("产品名称");
    }
    if (sFundName == "" || sFundName == null) {
      requiredAddTip.push("产品简称");
    }
    if (requiredAddTip.length > 0) {
      let requiredAddTips = requiredAddTip.join("、");
      window['swal']("提示", "请填写:" + requiredAddTips, "warning");
      return false;
    } else {
      return true;
    }
  }

  //  获取上传文件的文件名
  getFileName(value) {
    // 兼容ie title不出现问题
    this.fileName = value;
  }

  // 计算合同到期日
  countMonth() {
    if (this.otoAddOrEditBody.dBegin && this.otoAddOrEditBody.nContractPeriod) {
      this.otoAddOrEditBody.dEnd = moment(this.otoAddOrEditBody.dBegin).add(this.otoAddOrEditBody.nContractPeriod, 'months').format('YYYY-MM-DD')
    } else {
      this.otoAddOrEditBody.dEnd = '';
    }
  }

  //  截取文件名称类型
  InterceptType(item) {
    let str = item;
    if (str) {
      let arr = str.split('.');
      let newarr = arr[arr.length - 1];
      return newarr;
    }
  }
  //控制未成立新增和编辑3个字段不可编辑
  ctrlDisabled() {
    if (this.index == 'wcl' || this.index == 'new') {
      window['$']('#dBegin').attr("disabled", "disabled");
      window['$']('#dBegin').css("background", "#eeeeee");
      window['$']('#dEnd').attr("disabled", "disabled");
      window['$']('#dEnd').css("background", "#eeeeee");
      window['$']('#sFundCode').attr("disabled", "disabled");
      window['$']('#sFundCode').css("background", "#eeeeee");
    } else {
      window['$']('#dBegin').removeAttr("disabled");
      window['$']('#dEnd').removeAttr("disabled");
      window['$']('#sFundCode').removeAttr("disabled");
    }
  }
  // 导出客户信息
  exportInfo(nFundNo) {
    let that = this;
    let getBody = {
      "nFundNo": nFundNo,
    }
    const iframe = window['$']("<iframe id='downloadiframe'>");
    iframe.attr('style', 'display:none');
    //  转码，兼容ie
    getBody.nFundNo = encodeURI(getBody.nFundNo)
    iframe.attr('src', environment.server + '/pms/v1/customer/export?token=' + sessionStorage.getItem('token') + '&nFundNo=' + getBody.nFundNo);
    window['$']('body').append(iframe);
    setTimeout("$('#downloadiframe').remove()", 60000);
  }
  // 获取备案机构、受托人、托管人下拉框值
  getDictionary() {
    let that = this;
    this.oneEditService.getDictionary().subscribe(data => {
      if (data) {
        that.distionary.RECORDORG_TYPE = data.RECORDORG_TYPE;
        that.distionary.LINK_PRINCIPAL_NO = data.LINK_PRINCIPAL_NO;
        that.distionary.TRUSTEE = data.TRUSTEE;
      }
    })
  }
  // 点击表格头排序
  orderData(colName) {
    let listDataAsc = _.orderBy(this.otoManagerList, [colName], ["asc"]);
    if (JSON.stringify(this.otoManagerList) == JSON.stringify(listDataAsc)) {
      listDataAsc = _.orderBy(this.otoManagerList, [colName], ["desc"]);
    }
    this.otoManagerList = listDataAsc;
  }
}
